<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ page import="com.onlineMIS.ORM.entity.headQ.barcodeGentor.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改条型码资料</title>
<%@ include file="../../common/Style.jsp"%>
<script>
$(document).ready(function(){
	parent.$.messager.progress('close'); 
	$("#org_table tr").mouseover(function(){      
		$(this).addClass("over");}).mouseout(function(){    
		$(this).removeClass("over");}); 
	$("#clearBt").removeAttr("disabled");
});

function del(){
	var info = "你确定删除此商品条码信息?\n此商品信息一经删除所有相关单据都将删除对应信息!";
	if (confirm(info)){
	    var params=$("#updateProductForm").serialize();  
	    $.post("action/productJSONAction!checkBarcode",params, backProcess,"json");
	} 
}
function backProcess(data){
	var result = data.result;
	if (result == false){
	  document.updateProductForm.action = "action/productJSPAction!delete";
	  document.updateProductForm.submit();
	} else {
	  alert("此条码已经使用无法删除！");
	}
}
function update(){
	var error ="";
	if ($("#productCode").val() == ""){
		error +="产品货号 - 不能为空\n";
		$("#productCode").focus();
	} 	
	
	if ($("#brand_ID").val() == ""){
		error +="产品牌 - 不能为空\n";
	} 	
	var categoryLevelId = $("#category_level_ID").combo("getValue");
	if (categoryLevelId != "0" && !isValidPositiveInteger(categoryLevelId)){
		alert("产品线类型不是一个正确的输入");
		return;
	}

	
	var categoryId = $("#category").combo("getValue");
	if (categoryId != "0" && !isValidPositiveInteger(categoryId)){
		alert("货品类别不是一个正确的输入");
		return;
	}
	
	var colorId = $("#colorId").combo("getValue");
	if (!isValidPositiveInteger(categoryId)){
		alert("颜色不是一个正确的输入");
		return;
	}
	
	var priceValue = $("#salesPrice").val();
	if (priceValue != "" && isNaN(priceValue)){
        error += "连锁店零售价 - 必须是数字\n";
        $("#salesPrice").focus();
	} else if (priceValue != "" && priceValue == 0){
        $("#salesPrice").val("");
	} 
	
	var costMultiple = $("#costMultiple").val();
	if (costMultiple != "" && isNaN(costMultiple)){
        error += "成本倍数 - 必须是数字\n";
        $("#costMultiple").focus();
	} else if (costMultiple != "" && costMultiple == 0){
        $("#costMultiple").val("");
	}

	var recCostValue = $("#recCost").val();
	if (recCostValue != "" && isNaN(recCostValue)){
        error += "进价 - 必须是数字\n";
        $("#recCost").focus();
	} else if (recCostValue != "" && recCostValue == 0){
        $("#recCost").val("");
	} 
	
	var wholePriceValue = $("#wholeSalePrice").val();
	if (wholePriceValue != "" && isNaN(wholePriceValue)){
        error += "预设价1 - 必须是数字\n";
        $("#wholeSalePrice").focus();
	} else if (wholePriceValue != "" && wholePriceValue == 0){
        $("#wholeSalePrice").val("");
	} 

	var wholePriceValue2 = $("#wholeSalePrice2").val();
	if (wholePriceValue2 != "" && isNaN(wholePriceValue2)){
        error += "预设价2 - 必须是数字\n";
        $("#wholeSalePrice").focus();
	} else if (wholePriceValue2 != "" && wholePriceValue2 == 0){
        $("#wholeSalePrice2").val("");
	} 

	var wholePriceValue3 = $("#wholeSalePrice3").val();
	if (wholePriceValue3 != "" && isNaN(wholePriceValue3)){
        error += "预设价3 - 必须是数字\n";
        $("#wholeSalePrice3").focus();
	} else if (wholePriceValue3 != "" && wholePriceValue3 == 0){
        $("#wholeSalePrice3").val("");
	} 

	var salesPriceFactoryValue = $("#salesPriceFactory").val();
	if (salesPriceFactoryValue != "" && isNaN(salesPriceFactoryValue)){
        error += "厂家零售价 - 必须是数字\n";
        $("#salesPriceFactory").focus();
	} else if (salesPriceFactoryValue != "" && salesPriceFactoryValue == 0){
        $("#salesPriceFactory").val("");
	} 

	var discountValue = $("#discount").val();
	if (discountValue != "" && isNaN(discountValue)){
        error += "折扣 - 必须是数字\n";
        $("#discount").focus();
	} else if (discountValue != "" && (discountValue < 0 || discountValue >1)){
        error += "折扣 - 必须是小于或者等于1的正数\n";
        $("#discount").focus();
	} else if (discountValue != "" && discountValue == 0){
        $("#discount").val("");
	} 
	
	if (error != "")
	    $.messager.alert('错误', error, 'error');
	else {
		document.updateProductForm.action = "action/productJSPAction!update";
		document.updateProductForm.submit();
	}
}


/** 清除图片 */
function clearImage(){
	$("#img").attr('src', '<%=request.getContextPath()%>/conf_files/web-image/default.png'); 
}

/**实现图片预览*/
function change_photo(){
        PreviewImage($("input[name='formBean.inventory']")[0], 'img', 'imgtd');
             
    	var data = new FormData($('#uploadFrom')[0]);

    }

function PreviewImage(fileObj,imgPreviewId,divPreviewId){  
    var allowExtention=".jpg,.bmp,.gif,.png";              //允许上传文件的后缀名document.getElementById("hfAllowPicSuffix").value;  
    var extention=fileObj.value.substring(fileObj.value.lastIndexOf(".")+1).toLowerCase();              
    var browserVersion= window.navigator.userAgent.toUpperCase();  
    if(allowExtention.indexOf(extention)>-1){   
        if(fileObj.files){                                 //HTML5实现预览，兼容chrome、火狐7+等  
            if(window.FileReader){  
                var reader = new FileReader();   
                reader.onload = function(e){  
                    document.getElementById(imgPreviewId).setAttribute("src",e.target.result);  
                }    
                reader.readAsDataURL(fileObj.files[0]);  
            }else if(browserVersion.indexOf("SAFARI")>-1){  
                alert("不支持Safari6.0以下浏览器的图片预览!");  
            }  
        }else if (browserVersion.indexOf("MSIE")>-1){  
            if(browserVersion.indexOf("MSIE 6")>-1){//ie6  
                document.getElementById(imgPreviewId).setAttribute("src",fileObj.value);  
            }else{//ie[7-9]  
                fileObj.select();  
                if(browserVersion.indexOf("MSIE 9")>-1)  
                    fileObj.blur();//不加上document.selection.createRange().text在ie9会拒绝访问  
                var newPreview =document.getElementById(divPreviewId+"New");  
                if(newPreview==null){  
                    newPreview =document.createElement("div");  
                    newPreview.setAttribute("id",divPreviewId+"New");  
                    newPreview.style.width = document.getElementById(imgPreviewId).width+"px";  
                    newPreview.style.height = document.getElementById(imgPreviewId).height+"px";  
                    newPreview.style.border="solid 1px #d2e2e2";  
                }  
                newPreview.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale',src='" + document.selection.createRange().text + "')";                              
                var tempDivPreview=document.getElementById(divPreviewId);  
                tempDivPreview.parentNode.insertBefore(newPreview,tempDivPreview);  
                tempDivPreview.style.display="none";                      
            }  
        }else if(browserVersion.indexOf("FIREFOX")>-1){//firefox  
            var firefoxVersion= parseFloat(browserVersion.toLowerCase().match(/firefox\/([\d.]+)/)[1]);  
            if(firefoxVersion<7){//firefox7以下版本  
                document.getElementById(imgPreviewId).setAttribute("src",fileObj.files[0].getAsDataURL());  
            }else{//firefox7.0+                      
                document.getElementById(imgPreviewId).setAttribute("src",window.URL.createObjectURL(fileObj.files[0]));  
            }  
        }else{  
            document.getElementById(imgPreviewId).setAttribute("src",fileObj.value);  
        }           
    }else{  
        alert("仅支持"+allowExtention+"为后缀名的文件!");  
        fileObj.value="";//清空选中文件  
        if(browserVersion.indexOf("MSIE")>-1){                          
            fileObj.select();  
            document.selection.clear();  
        }                  
        fileObj.outerHTML=fileObj.outerHTML;  
    }  
}

</script>
</head>
<body>
	<table width="90%" align="center" class="OuterTable">
		<tr>
			<td><s:form id="updateProductForm" name="updateProductForm"
					method="post" action="" theme="simple">
					<table width="100%" border="0" id="org_table">
						<tr class="PBAOuterTableTitale">
							<th colspan="2">修改条形码信息</th>
						</tr>
						<tr>
							<td colspan="2"><div class="errorAndmes">
									<s:actionerror cssStyle="color:red" />
									<s:actionmessage cssStyle="color:blue" />
								</div></td>
						</tr>
						<tr class="InnerTableContent"
							style="background-color: rgb(255, 250, 208);">
							<td height="18"><strong>归属</strong> :</td>
							<td><s:if test="uiBean.product.chainStore != null">
									<s:property value="uiBean.product.chainStore.chain_name" />
								</s:if> <s:else>
	                		总部
	              </s:else></td>
						</tr>
						<tr class="InnerTableContent">
							<td height="18"><strong>商品编码</strong> :</td>
							<td><s:property value="uiBean.product.product.serialNum" /></td>

						</tr>
						<tr class="InnerTableContent"
							style="background-color: rgb(255, 250, 208);">
							<td height="18"><strong>条形码</strong> :</td>
							<td><s:property value="uiBean.product.barcode" /> <input
								type="hidden" name="formBean.productBarcode.barcode"
								value="<s:property value="uiBean.product.barcode"/>" /> <input
								type="hidden" name="formBean.productBarcode.id"
								value="<s:property value="uiBean.product.id"/>" /> <input
								type="hidden" name="formBean.productBarcode.product.productId"
								value="<s:property value="uiBean.product.product.productId"/>" />
							</td>
						</tr>
						<tr class="InnerTableContent"
							style="background-color: rgb(255, 250, 208);">
							<td height="18"><strong>公司货号</strong> :</td>
							<td><s:property value="uiBean.product.product.productIdentity" /> 
							</td>
						</tr>
						<tr class="InnerTableContent">
							<td height="18"><strong>品牌 </strong> :</td>
							<td><%@ include file="SearchBrandStub.jsp"%></td>
						</tr>
						<tr class="InnerTableContent">
							<td height="18" style="background-color: rgb(255, 250, 208);"><strong>年份 </strong> :</td>
							<td><s:select
									name="formBean.productBarcode.product.year.year_ID" size="1"
									id="year" list="uiBean.basicData.yearList" listKey="year_ID"
									listValue="year" /></td>
						</tr>
						<tr class="InnerTableContent"
							>
							<td height="18"><strong>季度</strong> :</td>
							<td><s:select
									name="formBean.productBarcode.product.quarter.quarter_ID"
									size="1" id="quarter" list="uiBean.basicData.quarterList"
									listKey="quarter_ID" listValue="quarter_Name" /></td>
						</tr>
						<tr class="InnerTableContent">
							<td height="18" style="background-color: rgb(255, 250, 208);"><strong>产品线</strong> :</td>
							<td><s:select
									name="formBean.productBarcode.product.categoryLevel1.category_ID"
									style="width:130px" cssClass="easyui-combobox" size="1"
									id="category_level_ID"
									list="uiBean.basicData.categoryLevelList" listKey="category_ID"
									listValue="category_Name" /></td>
						</tr>
						<tr class="InnerTableContent">
							<td height="18"><strong>类别</strong> :</td>
							<td><s:select
									name="formBean.productBarcode.product.category.category_ID"
									cssClass="easyui-combobox" size="1" id="category"
									list="uiBean.basicData.categoryList" listKey="category_ID"
									listValue="category_Name" /></td>
						</tr>
						<tr class="InnerTableContent"
							style="background-color: rgb(255, 250, 208);">
							<td height="18"><strong>产品货号</strong>:</td>
							<td><s:textfield
									name="formBean.productBarcode.product.productCode"
									id="productCode" />*</td>
						</tr>

						<tr class="InnerTableContent">
							<td height="18"><strong>齐码数量 </strong> :</td>
							<td><s:select
									name="formBean.productBarcode.product.numPerHand" size="1"
									id="numPerHand" list="uiBean.basicData.numPerHandList"
									listKey="numPerHand" listValue="numPerHand" /></td>
						</tr>
						<tr class="InnerTableContent"
							style="background-color: rgb(255, 250, 208);">
							<td height="18"><strong>单位 </strong> :</td>
							<td><s:select name="formBean.productBarcode.product.unit"
									size="1" id="unit" list="uiBean.basicData.unitList"
									listKey="productUnit" listValue="productUnit" /></td>
						</tr>
						<tr class="InnerTableContent">
							<td height="18"><strong>颜色</strong> :</td>
							<td><s:select name="formBean.productBarcode.color.colorId"
									cssClass="easyui-combobox"
									size="1" id="colorId" list="uiBean.basicData.colorList"
									listKey="colorId" listValue="name" headerKey="" headerValue=""/></td>
						</tr>
						<tr class="InnerTableContent"
							style="background-color: rgb(255, 250, 208);">
							<td height="18"><strong>最小码</strong> :</td>
							<td><s:select id="sizeMin" name="formBean.productBarcode.product.sizeMin"  list="#{'60':'60','70':'70','80':'80','90':'90','100':'100','110':'110','120':'120','130':'130','140':'140','150':'150','160':'160','170':'170'}" listKey="key" listValue="value" headerKey="0" headerValue="--" />
							</td>
						</tr>
						<tr class="InnerTableContent"
							style="background-color: rgb(255, 250, 208);">
							<td height="18"><strong>最大码</strong> :</td>
							<td><s:select id="sizeMax" name="formBean.productBarcode.product.sizeMax"  list="#{'110':'110','120':'120','130':'130','140':'140','150':'150','160':'160','170':'170','180':'180','190':'190'}" listKey="key" listValue="value" headerKey="0" headerValue="--" />
							</td>
						</tr>
						<tr class="InnerTableContent"
							style="background-color: rgb(255, 250, 208);">
							<td height="18"><strong>面料</strong> :</td>
							<td><s:textfield cssClass="easyui-textbox"
									name="formBean.productBarcode.product.material" id="material" /></td>
						</tr>
						<tr class="InnerTableContent">
							<td height="18"><strong>千禧吊牌价 </strong> :</td>
							<td><input type="text"
								name="formBean.productBarcode.product.salesPrice"
								id="salesPrice"
								value="<s:if test="uiBean.product.product.salesPrice!=0"><s:property value="uiBean.product.product.salesPrice"/></s:if>"
								size="10" /></td>
						</tr>
						<tr class="InnerTableContent"
							style="background-color: rgb(255, 250, 208);">
							<td height="18"><strong>进价 </strong> :</td>
							<td><input type="text"
								name="formBean.productBarcode.product.recCost" id="recCost"
								value="<s:if test="uiBean.product.product.recCost!=0"><s:property value="uiBean.product.product.recCost"/></s:if>"
								size="10" /></td>
						</tr>
						<tr class="InnerTableContent"
							style="background-color: rgb(255, 250, 208);">
							<td height="18"><strong>成本倍数 </strong> :</td>
							<td><input type="text"
								name="formBean.productBarcode.product.costMultiple"
								id="costMultiple"
								value="<s:if test="uiBean.product.product.costMultiple!=0"><s:property value="uiBean.product.product.costMultiple"/></s:if>"
								size="10" /></td>
						</tr>
						<tr class="InnerTableContent">
							<td height="18"><strong>预设价1 </strong> :</td>
							<td><input type="text"
								name="formBean.productBarcode.product.wholeSalePrice"
								id="wholeSalePrice"
								value="<s:if test="uiBean.product.product.wholeSalePrice!=0"><s:property value="uiBean.product.product.wholeSalePrice"/></s:if>"
								size="10" /></td>
						</tr>
						<tr class="InnerTableContent"
							style="background-color: rgb(255, 250, 208);">
							<td height="18"><strong>预设价2 </strong> :</td>
							<td><input type="text"
								name="formBean.productBarcode.product.wholeSalePrice2"
								id="wholeSalePrice2"
								value="<s:if test="uiBean.product.product.wholeSalePrice2!=0"><s:property value="uiBean.product.product.wholeSalePrice2"/></s:if>"
								size="10" /></td>
						</tr>
						<tr class="InnerTableContent">
							<td height="18"><strong>预设价3 </strong> :</td>
							<td><input type="text"
								name="formBean.productBarcode.product.wholeSalePrice3"
								id="wholeSalePrice3"
								value="<s:if test="uiBean.product.product.wholeSalePrice3!=0"><s:property value="uiBean.product.product.wholeSalePrice3"/></s:if>"
								size="10" /></td>
						</tr>
						<tr class="InnerTableContent"
							style="background-color: rgb(255, 250, 208);">
							<td height="18"><strong>厂家零售价 </strong> :</td>
							<td><input type="text"
								name="formBean.productBarcode.product.salesPriceFactory"
								id="salesPriceFactory"
								value="<s:if test="uiBean.product.product.salesPriceFactory!=0"><s:property value="uiBean.product.product.salesPriceFactory"/></s:if>"
								size="10" /></td>
						</tr>
						<tr class="InnerTableContent">
							<td height="18"><strong>折扣 </strong> :</td>
							<td><input type="text"
								name="formBean.productBarcode.product.discount" id="discount"
								value="<s:if test="uiBean.product.product.discount!=0"><s:property value="uiBean.product.product.discount"/></s:if>"
								size="10" /></td>
						</tr>
<!-- 					<tr class="InnerTableContent" style="background-color: rgb(255, 250, 208);">
							<td height="18">图片:</td>
							<td><input class="easyui-filebox" id="picture" 
								name="formBean.inventory"  buttonText="上传" buttonIcon="icon-ok" style="width: 180px"
								data-options="prompt:'请上传图片',onChange:change_photo,accept:'image/jpeg,image/png'">
								<a href="#" id="clearBt" class="easyui-linkbutton"  onclick="clearImage();"  data-options="iconCls:'icon-no',toggle:true">清除</a>
								</td>
						</tr>
						<tr class="InnerTableContent" style="background-color: rgb(255, 250, 208);">
							<td height="18">本次修改图片:</td>
							<td rowspan="2" id="imgtd"><img id="img" src="<%=request.getContextPath()%>/conf_files/web-image/default.png"
								style="height: 90px; width: 130px" />
						</tr>
						<tr class="InnerTableContent" style="background-color: rgb(255, 250, 208);">
							<td height="18"></td>
							<td></td>
						</tr>
						<tr class="InnerTableContent">
							<td height="18">已上传图片:</td>
							<td rowspan="2" ><img id="uploaded" src="'imgPath'+<s:property value="uiBean.product.product.discount"/>"
								style="height: 90px; width: 130px" />
						</tr>
						<tr class="InnerTableContent">
							<td height="18"></td>
							<td></td>
						</tr> -->	
						<tr class="InnerTableContent"
							style="background-color: rgb(255, 250, 208);">
							<td colspan="2"><input type="button" value="更新"
								onclick="update();" />&nbsp;&nbsp;<input type="button"
								value="删除" onclick="del();" />&nbsp;&nbsp;<input type="button"
								value="取消" onclick="window.close();" /></td>
						</tr>
					</table>
				</s:form></td>
		</tr>
	</table>
</body>
</html>